<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app">
        <v-a></v-a>
        <v-b></v-b>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/pubsub-js/1.9.0/pubsub.min.js"></script>
<script src="../js/vue.js"></script>
<script>
    Vue.config.productionTip = false;
    var vm = new Vue({
        el:"#app",
        components:{
            "v-a":{
                data(){
                  return {
                      msg:"v-a"
                  }
                },
                template:"<strong @click='clickFn'>{{msg}}</strong>",
                methods:{
                    clickFn(){
                       //pubsub进行发布
                        PubSub.publish('updateMsg', this.msg);
                    }
                }
            },
            "v-b":{
                data(){
                    return {
                        msg:"v-b"
                    }
                },
                template:"<strong>{{msg}}</strong>",
                mounted(){
                    //pubsub订阅
                    PubSub.subscribe('updateMsg', function (name, msg) {
                        this.msg = msg
                    }.bind(this));
                }
            }
        }
    })
</script>
</html>